package com.oedtech.esl.repository.esl;

import com.oedtech.esl.model.esl.EslImg;
import org.junit.Test;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @Author QiuLongYu
 * @Date 2019/7/26
 */
@Repository
public interface EslImgDao extends JpaSpecificationExecutor<EslImg>,JpaRepository<EslImg,Long> {

    @Transactional
    @Modifying
    @Query(value = "INSERT INTO esl_img (tiny_ip,img_path,name,page,bin_path) VALUES (?1,?2,?3,?4,?5) " +
            " ON DUPLICATE KEY UPDATE img_path=VALUES(img_path),name=VALUES(name),page=VALUES(page),bin_path=VALUES(bin_path)",nativeQuery = true)
    int insertOrUpdateImg(String tinyIP,String img,String name,Integer page,String bin_path);

    @Transactional
    @Modifying
    @Query( value = "delete from esl_img where tiny_ip in(?1)",nativeQuery = true)
    int deleteByTinyIP(List<String> tinyIPs);
}
